import java.security.PublicKey;

public class HashBuck {
    public static final double DEFAULT_LOAD_FACTOR=0.75f;
    public Node[] arrayNode = new Node[10];
    public int usedSize;

    static class Node{
        public int key;
        public int val;
        public Node next;

        public Node(int key, int val) {
            this.key = key;
            this.val = val;
        }
    }

    public void push(int key,int val){
        int index = key % arrayNode.length;
        Node cur = arrayNode[index];
        while(cur!=null){
            if (cur.key==key){
                cur.val=val;
                return;
            }
            cur=cur.next;
        }
        Node curN = new Node(key,val);
        curN.next = arrayNode[index];
        arrayNode[index]=curN;
        usedSize++;
        if(doLOADFACTOR()>=DEFAULT_LOAD_FACTOR){
            resize();
        }
    }
    private double doLOADFACTOR(){
        return usedSize*1.0/ arrayNode.length;
    }

    private void resize(){
        Node[] newarrayNode = new Node[2* arrayNode.length];
        for (int i=0;i< arrayNode.length;i++){
            Node cur = arrayNode[i];
            while(cur!=null){
                Node curN=null;
                int newIndex= cur.key% newarrayNode.length;
                curN=cur.next;

                cur.next=newarrayNode[newIndex];
                newarrayNode[newIndex] = cur;
                cur=curN;
            }
        }
        arrayNode=newarrayNode;
    }
    public int getVal(int key){
        int index = key %arrayNode.length;
        Node cur = arrayNode[index];
        while(cur!=null){
            if (cur.key==key){
                return cur.val;
            }
            cur=cur.next;
        }
        return -1;
    }
}
